/*
 * Funny Language - a free style programming language.
 * Copyright (C) 2015 by fanguangping (fanguangping@163.com)
 * lexer.h
 */

#ifndef FUNNY_LEXER_H
#define FUNNY_LEXER_H

#include "../base/utils.h"
#include "../ds/datastructure.h"

#define RULE  0
#define GROUP 1
#define TOKEN 2

typedef struct _Rule {
    int type;
    union {
        char *regex;
        Queue *patterns;
    };
} Rule;

typedef struct _Pattern {
    String regex;
    String target;
} Pattern;

String replace_string_with_number(String orig, char open, char close, char escape);
Rule *alloc_rule();
Pattern *init_pattern(String regex, String target);
String lex_to_function(String token, String text);
String expand_lex(String text);
void init_lexer();
void register_rule(String token, Queue *patterns);
void register_group(String token, Queue *patterns);
void register_token(String token, String regex);
void cache_patterns();

#endif //FUNNY_LEXER_H
